﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using StateGrid.MDBservice;
using System.IO;
using iTextSharp.text.pdf;

namespace StateGrid.KJCG
{
    class KJCG_MDB : MDBservice.MDBservice
    {
        public override String id
        {
            get
            {
                return "kejichengguo";
            }
        }

        private KJCG_DAO kjcgDAO = new KJCG_DAO();

        public override void clear()
        {
            base.clear();
        }

        public override String getTest()
        {
            IList<KJCG_FL> r = kjcgDAO.GetAllKJCG_FL();
            String ret = String.Empty;
            foreach (KJCG_FL i in r)
            {
                ret += i.ToString();
            }
            return ret;
        }

        public KJCG_MDB()
        {
            pmTableName = "KJCG_WF";
            formatPmTableName = "KJCG";
            title = "科技成果";
        }

        public override void setColumnList()
        {
            this.ColumnList = new List<Column>();
            if (hasFormatTable)
            {
                this.ColumnList.Add(new Column("分类编码", OleDbType.WChar, 12));
                this.ColumnList.Add(new Column("专业代码", OleDbType.WChar, 30));
                this.ColumnList.Add(new Column("成果代码", OleDbType.WChar, 20));
                this.ColumnList.Add(new Column("上报编码", OleDbType.WChar, 40));
                this.ColumnList.Add(new Column("中文名称", OleDbType.WChar, 250));
                this.ColumnList.Add(new Column("成果类别", OleDbType.WChar, 20));
                this.ColumnList.Add(new Column("起始日期", OleDbType.Date));
                this.ColumnList.Add(new Column("终止日期", OleDbType.Date));
                this.ColumnList.Add(new Column("学科代码", OleDbType.WChar, 60));
                this.ColumnList.Add(new Column("国图分类", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("中文主题词", OleDbType.WChar, 255));
                this.ColumnList.Add(new Column("中文文摘", OleDbType.WChar, 0));
                this.ColumnList.Add(new Column("课题来源", OleDbType.WChar, 100));
                this.ColumnList.Add(new Column("评价方式", OleDbType.WChar, 100));
                this.ColumnList.Add(new Column("评价单位", OleDbType.WChar, 100));
                this.ColumnList.Add(new Column("评价日期", OleDbType.Date));
                this.ColumnList.Add(new Column("评价意见", OleDbType.WChar, 0));
                this.ColumnList.Add(new Column("奖项名称", OleDbType.WChar, 200));
                this.ColumnList.Add(new Column("奖励单位", OleDbType.WChar, 200));
                this.ColumnList.Add(new Column("奖励年度", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("授奖等级", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("产权形式", OleDbType.WChar, 20));
                this.ColumnList.Add(new Column("产权名称", OleDbType.WChar, 250));
                this.ColumnList.Add(new Column("产权标识", OleDbType.WChar, 250));
                this.ColumnList.Add(new Column("第一单位", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("单位属性", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("隶属关系", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("通讯地址", OleDbType.WChar, 70));
                this.ColumnList.Add(new Column("邮政编码", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("联系电话", OleDbType.WChar, 80));
                this.ColumnList.Add(new Column("传真电话", OleDbType.WChar, 80));
                this.ColumnList.Add(new Column("联系人", OleDbType.WChar, 30));
                this.ColumnList.Add(new Column("电子信箱", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("其他单位", OleDbType.WChar, 255));
                this.ColumnList.Add(new Column("第一完成人", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("性别", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("职务职称", OleDbType.WChar, 50));
                this.ColumnList.Add(new Column("所在单位", OleDbType.WChar, 200));
                this.ColumnList.Add(new Column("电话", OleDbType.WChar, 250));
                this.ColumnList.Add(new Column("其他完成人", OleDbType.WChar, 0));
                this.ColumnList.Add(new Column("推荐单位意见", OleDbType.WChar, 0));
                this.ColumnList.Add(new Column("更新日期", OleDbType.Date));
                this.ColumnList.Add(new Column("共享", OleDbType.Boolean));
            }
            else
            {
                //未支持
            }
        }

        protected override PM getPM(OleDbDataReader reader, out String err)
        {
            err = String.Empty;
            KJCG_PM pm = new KJCG_PM();
            if (hasFormatTable)
            {
                pm.flbm = reader["分类编码"].ToString().Trim();
                pm.zydm = reader["专业代码"].ToString().Trim();
                pm.cgdm = reader["成果代码"].ToString().Trim();
                pm.sbbm = reader["上报编码"].ToString().Trim();
                pm.zwmc = reader["中文名称"].ToString().Trim();
                pm.cglb = reader["成果类别"].ToString().Trim();
                try
                {
                    if (String.Empty.Equals(reader["起始日期"].ToString().Trim()))
                    {
                        //err += pm.flbm + "-" + pm.cgdm + ":" + pm.zwmc + ":起始日期为空\n";
                        pm.qsrq = null;
                    }
                    else
                        pm.qsrq = DateTime.Parse(reader["起始日期"].ToString().Trim());
                }
                catch
                {
                    err += pm.flbm + "-" + pm.cgdm + ":" + pm.zwmc + ": 起始日期\"" + reader["起始日期"] + "\"出错\n";
                }
                try
                {
                    if (String.Empty.Equals(reader["终止日期"].ToString().Trim()))
                    {
                        //err += pm.flbm + "-" + pm.cgdm + ":" + pm.zwmc + ":终止日期为空\n";
                        pm.zzrq = null;
                    }
                    else
                        pm.zzrq = DateTime.Parse(reader["终止日期"].ToString().Trim());
                }
                catch
                {
                    err += pm.flbm + "-" + pm.cgdm + ":" + pm.zwmc + ": 终止日期\"" + reader["终止日期"] + "\"出错\n";
                }
                pm.xkdm = reader["学科代码"].ToString().Trim();
                pm.gtfl = reader["国图分类"].ToString().Trim();
                pm.zwztc = reader["中文主题词"].ToString().Trim();
                pm.zwwz = reader["中文文摘"].ToString().Trim();
                pm.ktly = reader["课题来源"].ToString().Trim();
                pm.pjfs = reader["评价方式"].ToString().Trim();
                pm.pjdw = reader["评价单位"].ToString().Trim();
                try
                {
                    if (String.Empty.Equals(reader["评价日期"].ToString().Trim()))
                    {
                        //err += pm.flbm + "-" + pm.cgdm + ":" + pm.zwmc + ":评价日期为空\n";
                        pm.pjrq = null;
                    }
                    else
                        pm.pjrq = DateTime.Parse(reader["评价日期"].ToString().Trim());
                }
                catch
                {
                    err += pm.flbm + "-" + pm.cgdm + ":" + pm.zwmc + ": 评价日期\"" + reader["评价日期"] + "\"出错\n";
                }
                pm.pjyj = reader["评价意见"].ToString().Trim();
                pm.jxmc = reader["奖项名称"].ToString().Trim();
                pm.jldw = reader["奖励单位"].ToString().Trim();
                pm.jlnd = reader["奖励年度"].ToString().Trim();
                pm.sjdj = reader["授奖等级"].ToString().Trim();
                pm.cqxs = reader["产权形式"].ToString().Trim();
                pm.cqmc = reader["产权名称"].ToString().Trim();
                pm.cqbs = reader["产权标识"].ToString().Trim();
                pm.dydw = reader["第一单位"].ToString().Trim();
                pm.dwsx = reader["单位属性"].ToString().Trim();
                pm.lsgx = reader["隶属关系"].ToString().Trim();
                pm.txdz = reader["通讯地址"].ToString().Trim();
                pm.yzbm = reader["邮政编码"].ToString().Trim();
                pm.lxdh = reader["联系电话"].ToString().Trim();
                pm.czdh = reader["传真电话"].ToString().Trim();
                pm.lxr = reader["联系人"].ToString().Trim();
                pm.dzxx = reader["电子信箱"].ToString().Trim();
                pm.qtdw = reader["其他单位"].ToString().Trim();
                pm.dywcr = reader["第一完成人"].ToString().Trim();
                pm.xb = reader["性别"].ToString().Trim();
                pm.zwzc = reader["职务职称"].ToString().Trim();
                pm.szdw = reader["所在单位"].ToString().Trim();
                pm.dh = reader["电话"].ToString().Trim();
                pm.qtwcr = reader["其他完成人"].ToString().Trim();
                pm.tjdwyj = reader["推荐单位意见"].ToString().Trim();
                pm.gxrq = DateTime.Now;
                try
                {
                    pm.gx = Boolean.Parse(reader["共享"].ToString().Trim());
                }
                catch (Exception)
                {
                    pm.gx = false;
                }
            }
            else
            {
                //不支持
            }
            pm.dlr = user.name;
            pm.fillEmptyStringAsNull();
            return pm;
        }

        public override bool checkPMValid(PM pm, out string errMsg)
        {
            errMsg = String.Empty;
            KJCG_PM kjcg = (KJCG_PM)pm;
            this.openOleDbConnection();
            sqlcmd.CommandText = @"select * from " + formatPmTableName + " where 中文名称=@中文名称 and 第一单位=@第一单位 and 奖励年度=@奖励年度";
            sqlcmd.Connection = this.ObjConnection;
            sqlcmd.Parameters.Add(new OleDbParameter("中文名称", kjcg.zwmc));
            sqlcmd.Parameters.Add(new OleDbParameter("第一单位", kjcg.dydw));
            sqlcmd.Parameters.Add(new OleDbParameter("奖励年度", kjcg.jlnd));
            OleDbDataReader reader = sqlcmd.ExecuteReader();

            if (reader.Read())
            {
                reader.Close();
                sqlcmd.Parameters.Clear();
                return true;
            }
            else
            {
                reader.Close();
                sqlcmd.Parameters.Clear();
                return false;
            }
            //            this.closeOleDbConnection();
        }

        public override string formatData(PM pm)
        {
            //反馈信息
            String result = String.Empty;
            String Empty = "NULL";
            KJCG_PM kjcg = (KJCG_PM)pm;

            kjcg.gtfl = GlobalMethod.Semicolon(kjcg.gtfl);
            kjcg.zwztc = GlobalMethod.Semicolon(kjcg.zwztc);
            kjcg.dydw = GlobalMethod.Semicolon(kjcg.dydw);
            kjcg.qtdw = GlobalMethod.Semicolon(kjcg.qtdw);
            kjcg.qtwcr = GlobalMethod.Semicolon(kjcg.qtwcr);
            kjcg.dlr = user.name;
            kjcg.gxrq = DateTime.Now;
            //分类编码可能有多个，以分类隔开
            String[] flbms = kjcg.flbm.Split(';');
            foreach (string flbm in flbms)
            {
                if (kjcgDAO.GetKJCG_FLByFlbm(flbm) == null)
                {
                    result += "分类编码" + flbm + "不存在 ";
                }
            }
            if (Empty.Equals(kjcg.zwmc))
            {
                result += "中文名称为空 ";
            }
            if (kjcg.qsrq > kjcg.zzrq)
            {
                result += "起始日期晚于终止日期 ";
            }


            if (!result.Equals(String.Empty))
            {
                result += " : " + kjcg.szdw + kjcg.jlnd + "《" + kjcg.zwmc + "》\n";
            }

            return result;
        }

        public override String insertPM(PM pm)
        {
            KJCG_PM kjcg = (KJCG_PM)pm;
            int back;
            String err = String.Empty;
            //打开连接
            this.openOleDbConnection();
            OleDbCommand sqlcmd = new OleDbCommand();
            if (!String.Empty.Equals(validateTableName(formatPmTableName)))
            {
                sqlcmd.CommandText = @"create Table " + formatPmTableName + @"(分类编码 char(12), 专业代码 char(30), 成果代码 char(9), 上报编码 char(20), 中文名称 char(100), 成果类别 char(10), 起始日期 datetime, 终止日期 datetime, 学科代码 char(30), 国图分类 char(30), 中文主题词 char(100), 中文文摘 text, 课题来源 char(20), 评价方式 char(10), 评价单位 char(100), 评价日期 datetime, 评价意见 text, 奖项名称 char(30), 奖励单位 char(100), 奖励年度 char(20), 授奖等级 char(7), 产权形式 char(10), 产权名称 char(100), 产权标识 char(100), 第一单位 char(50), 单位属性 char(50), 隶属关系 char(50), 通讯地址 char(50), 邮政编码 char(50), 联系电话 char(30), 传真电话 char(30), 联系人 char(10), 电子信箱 char(30), 其他单位 char(255), 第一完成人 char(8), 性别 char(2), 职务职称 char(10), 所在单位 char(50), 电话 char(30), 其他完成人 char(100), 推荐单位意见 text, 登录日期 datetime, 共享 boolean)";
                sqlcmd.Connection = this.ObjConnection;
                try
                {
                    back = sqlcmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    err = e.Message + "\n";
                    return err;
                }
            }

            sqlcmd.CommandText = @"insert into " + formatPmTableName + @"(分类编码,专业代码,成果代码,上报编码,中文名称,成果类别,起始日期,终止日期,学科代码,国图分类,中文主题词,中文文摘,课题来源,评价方式,评价单位,评价日期,评价意见,奖项名称,奖励单位,奖励年度,授奖等级,产权形式,产权名称,产权标识,第一单位,单位属性,隶属关系,通讯地址,邮政编码,联系电话,传真电话,联系人,电子信箱,其他单位,第一完成人,性别,职务职称,所在单位,电话,其他完成人,推荐单位意见,登录日期,共享) values(@分类编码,@专业代码,@成果代码,@上报编码,@中文名称,@成果类别,@起始日期,@终止日期,@学科代码,@国图分类,@中文主题词,@中文文摘,@课题来源,@评价方式,@评价单位,@评价日期,@评价意见,@奖项名称,@奖励单位,@奖励年度,@授奖等级,@产权形式,@产权名称,@产权标识,@第一单位,@单位属性,@隶属关系,@通讯地址,@邮政编码,@联系电话,@传真电话,@联系人,@电子信箱,@其他单位,@第一完成人,@性别,@职务职称,@所在单位,@电话,@其他完成人,@推荐单位意见,@登录日期,@共享)";
            sqlcmd.Connection = this.ObjConnection;
            OleDbParameter parameter;
            sqlcmd.Parameters.Add(new OleDbParameter("分类编码", kjcg.flbm));
            sqlcmd.Parameters.Add(new OleDbParameter("专业代码", kjcg.zydm));
            sqlcmd.Parameters.Add(new OleDbParameter("成果代码", kjcg.cgdm));
            sqlcmd.Parameters.Add(new OleDbParameter("上报编码", kjcg.sbbm));
            sqlcmd.Parameters.Add(new OleDbParameter("中文名称", kjcg.zwmc));
            sqlcmd.Parameters.Add(new OleDbParameter("成果类别", kjcg.cglb));
            parameter = new OleDbParameter("起始日期", OleDbType.DBDate);
            parameter.Value = kjcg.gxrq;
            sqlcmd.Parameters.Add(parameter);
            parameter = new OleDbParameter("终止日期", OleDbType.DBDate);
            parameter.Value = kjcg.gxrq;
            sqlcmd.Parameters.Add(parameter);
            sqlcmd.Parameters.Add(new OleDbParameter("学科代码", kjcg.yzbm));
            sqlcmd.Parameters.Add(new OleDbParameter("国图分类", kjcg.gtfl));
            sqlcmd.Parameters.Add(new OleDbParameter("中文主题词", kjcg.zwztc));
            sqlcmd.Parameters.Add(new OleDbParameter("中文文摘", kjcg.zwwz));
            sqlcmd.Parameters.Add(new OleDbParameter("课题来源", kjcg.ktly));
            sqlcmd.Parameters.Add(new OleDbParameter("评价方式", kjcg.pjfs));
            sqlcmd.Parameters.Add(new OleDbParameter("评价单位", kjcg.pjdw));
            parameter = new OleDbParameter("评价日期", OleDbType.DBDate);
            parameter.Value = kjcg.pjrq;
            sqlcmd.Parameters.Add(parameter);
            sqlcmd.Parameters.Add(new OleDbParameter("评价意见", kjcg.pjyj));
            sqlcmd.Parameters.Add(new OleDbParameter("奖项名称", kjcg.jxmc));
            sqlcmd.Parameters.Add(new OleDbParameter("奖励单位", kjcg.jldw));
            sqlcmd.Parameters.Add(new OleDbParameter("奖励年度", kjcg.jlnd));
            sqlcmd.Parameters.Add(new OleDbParameter("授奖等级", kjcg.sjdj));
            sqlcmd.Parameters.Add(new OleDbParameter("产权形式", kjcg.cqxs));
            sqlcmd.Parameters.Add(new OleDbParameter("产权名称", kjcg.cqmc));
            sqlcmd.Parameters.Add(new OleDbParameter("产权标识", kjcg.cqbs));
            sqlcmd.Parameters.Add(new OleDbParameter("第一单位", kjcg.dydw));
            sqlcmd.Parameters.Add(new OleDbParameter("单位属性", kjcg.dwsx));
            sqlcmd.Parameters.Add(new OleDbParameter("隶属关系", kjcg.lsgx));
            sqlcmd.Parameters.Add(new OleDbParameter("通讯地址", kjcg.txdz));
            sqlcmd.Parameters.Add(new OleDbParameter("邮政编码", kjcg.yzbm));
            sqlcmd.Parameters.Add(new OleDbParameter("联系电话", kjcg.lxdh));
            sqlcmd.Parameters.Add(new OleDbParameter("传真电话", kjcg.czdh));
            sqlcmd.Parameters.Add(new OleDbParameter("联系人", kjcg.lxr));
            sqlcmd.Parameters.Add(new OleDbParameter("电子信箱", kjcg.dzxx));
            sqlcmd.Parameters.Add(new OleDbParameter("其他单位", kjcg.qtdw));
            sqlcmd.Parameters.Add(new OleDbParameter("第一完成人", kjcg.dywcr));
            sqlcmd.Parameters.Add(new OleDbParameter("性别", kjcg.xb));
            sqlcmd.Parameters.Add(new OleDbParameter("职务职称", kjcg.zwzc));
            sqlcmd.Parameters.Add(new OleDbParameter("所在单位", kjcg.szdw));
            sqlcmd.Parameters.Add(new OleDbParameter("电话", kjcg.dh));
            sqlcmd.Parameters.Add(new OleDbParameter("其他完成人", kjcg.qtwcr));
            sqlcmd.Parameters.Add(new OleDbParameter("推荐单位意见", kjcg.tjdwyj));
            parameter = new OleDbParameter("登录日期", OleDbType.DBDate);
            parameter.Value = kjcg.gxrq;
            sqlcmd.Parameters.Add(parameter);
            parameter = new OleDbParameter("共享", OleDbType.Boolean);
            parameter.Value = kjcg.gx;
            sqlcmd.Parameters.Add(parameter);
            try
            {
                back = sqlcmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                err = e.Message + "\n";
            }
            sqlcmd.Parameters.Clear();

            this.closeOleDbConnection();
            return err;
        }

        public override int deletePM(PM pm, out String err)
        {
            int back = 0;
            err = String.Empty;
            KJCG_PM kjcg = (KJCG_PM)pm;
            //打开连接
            this.openOleDbConnection();
            OleDbCommand sqlcmd = new OleDbCommand();
            if (!String.Empty.Equals(validateTableName(formatPmTableName)))
            {
                sqlcmd.CommandText = @"create Table " + formatPmTableName + @"(分类编码 char(12), 专业代码 char(30), 成果代码 char(9), 上报编码 char(20), 中文名称 char(100), 成果类别 char(10), 起始日期 datetime, 终止日期 datetime, 学科代码 char(30), 国图分类 char(30), 中文主题词 char(100), 中文文摘 text, 课题来源 char(20), 评价方式 char(10), 评价单位 char(100), 评价日期 datetime, 评价意见 text, 奖项名称 char(30), 奖励单位 char(100), 奖励年度 char(20), 授奖等级 char(7), 产权形式 char(10), 产权名称 char(100), 产权标识 char(100), 第一单位 char(50), 单位属性 char(50), 隶属关系 char(50), 通讯地址 char(50), 邮政编码 char(50), 联系电话 char(30), 传真电话 char(30), 联系人 char(10), 电子信箱 char(30), 其他单位 char(255), 第一完成人 char(8), 性别 char(2), 职务职称 char(10), 所在单位 char(50), 电话 char(30), 其他完成人 char(100), 推荐单位意见 text, 登录日期 datetime, 共享 boolean)";
                sqlcmd.Connection = this.ObjConnection;
                try
                {
                    back = sqlcmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    err = e.Message + "\n";
                    return 0;
                }
            }
            //sql语句
            sqlcmd.CommandText = @"delete from " + formatPmTableName + " where 中文名称=@中文名称 and 第一单位=@第一单位 and 奖励年度=@奖励年度";
            sqlcmd.Connection = this.ObjConnection;
            sqlcmd.Parameters.Add(new OleDbParameter("中文名称", kjcg.zwmc));
            sqlcmd.Parameters.Add(new OleDbParameter("第一单位", kjcg.dydw));
            sqlcmd.Parameters.Add(new OleDbParameter("奖励年度", kjcg.jlnd));

            try
            {
                back = sqlcmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                err = "Exception: " + e.Message + "\n";
            }
            sqlcmd.Parameters.Clear();
            //            this.closeOleDbConnection();
            return back;
        }
        /* 现在的方法先delete再insert，就不用为每文库写update了
        public override bool updatePM(PM pm)
        {
            ZWQK_PM zwqk = (ZWQK_PM)pm;
            //打开连接
            this.openOleDbConnection();

            //sql语句
            OleDbCommand sqlcmd = new OleDbCommand(@"update ZWQK set 作者=@作者,作者单位=@作者单位,中文主题词=@中文主题词,外文主题词=@外文主题词,国图分类=@国图分类 where 中文篇名=@中文篇名 and 文件名=@文件名", this.ObjConnection);

            sqlcmd.Parameters.Add(new OleDbParameter("作者", zwqk.zz));
            sqlcmd.Parameters.Add(new OleDbParameter("作者单位", zwqk.zzdw));
            sqlcmd.Parameters.Add(new OleDbParameter("中文主题词", zwqk.zwztc));
            sqlcmd.Parameters.Add(new OleDbParameter("外文主题词", zwqk.wwztc));
            sqlcmd.Parameters.Add(new OleDbParameter("国图分类", zwqk.gtfl));
            sqlcmd.Parameters.Add(new OleDbParameter("中文篇名", zwqk.zwpm));
            sqlcmd.Parameters.Add(new OleDbParameter("文件名", zwqk.wjm));
            int back = sqlcmd.ExecuteNonQuery();
            if (back == 0)
            {
                return false;
            }
            //objConnection.Close();
            return true;
        }*/

        public override bool findServerDuplicate(PM pm)
        {
            KJCG_PM kjcg = (KJCG_PM)pm;
            KJCG_PM result = kjcgDAO.GetKJCG_PMByZwmcAndDydw(kjcg.zwmc, kjcg.dydw);
            if (result != null)
                return true;
            else
                return false;
        }

        public override String insertPMwithUpdateWJM(PM pm)
        {
            String err = String.Empty;
            KJCG_PM kjcg = (KJCG_PM)pm;
            //TODO:“成果代码”字段自动更新逻辑，待实现
/*            int index;
            index = kjcg.cgdm.LastIndexOf('-');
            int serial;
            KJCG_PM maxPm = kjcgDAO.getMaxKJCG_PM(kjcg.flbm, kjcg.nf.ToString(), kjcg.yf.ToString());
            if (maxPm != null)
            {
                int pos = maxPm.cgdm.LastIndexOf('-');
                int pos2 = maxPm.cgdm.LastIndexOf('.');
                serial = int.Parse(maxPm.cgdm.Substring(pos + 1, 4)) + 1;
            }
            else
            {
                serial = 1;
            }
            index = kjcg.ywjm.LastIndexOf('.');
            String suffixStr;
            if (index >= 0)
                suffixStr = kjcg.ywjm.Substring(index);
            else
                suffixStr = String.Empty;
            String serialStr = "0000" + serial.ToString();
            kjcg.wjm = kjcg.sybm + "-" + serialStr.Substring(serialStr.Length - 4) + suffixStr; */
            try
            {
                kjcgDAO.InsertKJCG_PM(kjcg);
            }
            catch (Exception e)
            {
                err += e.Message + "\n";
            }
            return err;
        }

        public override string addOneRecord(PM pm)
        {
            String err = String.Empty;
            KJCG_PM kjcg = (KJCG_PM)pm;
            kjcg.gxrq = DateTime.Now;
            kjcg.eraseNullInEmptyString();
            err += insertPMwithUpdateWJM(pm);
            return err;
        }

    }
}
